<template>
    <div class="logFund">
         <el-dialog 
            title="修改个人信息" 
            :visible.sync="dialog.show"
            :close-on-click-modal='false'
            :close-on-press-escape='false'
            :modal-append-to-body="false">
            <div class="form">
                <el-form 
                    ref="form" 
                    :model="form"
                    :rules="form_rules"
                    label-width="120px" 
                    style="margin:10px;width:auto;">  
                    <el-form-item prop='number'  label="学号:">
                        <el-input type="number"  v-model="form.number"></el-input>
                    </el-form-item>                                                    

                    <el-form-item prop='name' label="姓名:">
                        <el-input type="name" v-model="form.name"></el-input>
                    </el-form-item>                    

                    <el-form-item  class="text_right">
                        <el-button @click="dialog.show = false">取 消</el-button>
                        <el-button type="primary" @click='onSubmit("form")'>提  交</el-button>
                    </el-form-item>

                </el-form>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
  name: "DialogUser",
  props: {
    dialog: Object,
    form: Object
  },
  data() {
    return {
      form_rules: {
        number: [
          { required: true, message: "学号不能为空！", trigger: "blur" }
        ],       
        name: [{ required: true, message: "姓名不能为空！", trigger: "blur" }]
      },
    };
  },
  computed: {
    user() {
      return this.$store.getters.user;
    }
  },  
  methods: {      
    onSubmit(form) {
      this.$refs[form].validate(valid => {
        if (valid) {
          //表单数据验证完成之后，提交数据;
          const url =this.$store.getters.user.id;
          // 发送请求，修改个人信息
          this.$axios.post(`/api/users/editinfo/${url}`, this.form).then(res => {
            // 操作成功
            this.$message({
              message: "修改成功！",
              type: "success"
            });
            this.dialog.show = false;
            this.$emit("update");
          });
        }
      });
    }     
  }
};
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

